package cn.Testr;

import java.io.*;

/*本类用于复习序列化*/
public class Object12 {
    public static void main(String[] args) {
        mother1();//序列化
        mother();//反序列化
    }
    private static void mother() {
        ObjectInputStream in = null;
        try {
            in = new ObjectInputStream(new FileInputStream(new File("D:\\ready\\1.txt")));
            Object o=in.readObject();
            System.out.println(o);
            System.out.println("反序列化成功");
        } catch (Exception e) {
            System.out.println("反序列化失败");
            e.printStackTrace();
        }finally{
            try {
                in.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
    private static void mother1() {
        ObjectOutputStream out = null;

        try {
            out = new ObjectOutputStream(new FileOutputStream(new File("D:\\ready\\1.txt")));
            Is_A obj= new Is_A("hain",12,"dishf");
            out.writeObject(obj);
            System.out.println("序列化成功");
        } catch (IOException e) {
            System.out.println("序列化失败");
            e.printStackTrace();
        }finally {
            try {
                out.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}
